0

Is there any way to create a new form.php in Joomla to make this code work?

<?php
echo "<H2>Add a Car</H2><HR>";

function handleform()
{
    global $UserName, $UserCarMake, $UserCarModel, $UserCarYear, $UserCarColor, $UserCarPlate;

    $dbh=mysql_connect ("localhost", "username", "password");
    if (!dbh)
    {
        die("Failed to open the Database");
    }
    mysql_select_db("joomladatabase");
    if(mysql_errno())
    {
        die("<BR>" . mysql_errno().": ".mysql_error()."<BR>");
    }
    $query = "INSERT INTO RegisteredUserCars (UserName, UserCarMake, UserCarModel, UserCarYear, UserCarColor, UserCarPlate)
    VALUES ('$UserName', '$UserCarMake', '$UserCarModel', '$UserCarYear', '$UserCarColor', '$UserCarPlate')";
    $result = mysql_query($query);
    if (mysql_errno())
    {
        die("<BR>" . mysql_errno().": ".mysql_error()."<BR>");
    }
    else
    {
        echo "Database has been updated.";
    }
}
if ($beensubmitted)
{
    handleform();
}

?>

<FORM METHOD="POST" ACTION="AddRegisteredCars.php">

<P><B>Enter Your Car Make</B>
<BR><INPUT TYPE="TEXT" NAME="UserCarMake"></P>

<P><B>Enter Your Car Model</B>
<BR><INPUT TYPE="TEXT" NAME="UserCarModel"></P>

<P><B>Enter Your Car Year</B>
<BR><INPUT TYPE="TEXT" NAME="UserCarYear"></P>

<P><B>Enter Your Car Color</B>
<BR><INPUT TYPE="TEXT" NAME="UserCarColor"></P>

<P><B>Enter Your Car's License Plate Number</B>
<BR><INPUT TYPE="TEXT" NAME="UserCarPlate"></P>

<BR><INPUT TYPE="HIDDEN" NAME="beensubmitted" VALUE="TRUE">

<P><INPUT TYPE="SUBMIT" NAME="submit" VALUE="SUBMIT"></P>
</FORM>

When I click the submit button a new link pops up giving me a "404 not found" page. I don't know where to put the addregisteredcars.php file, and it's currently inside the XAMPP (Joomla 3.0) folder. Is there a different place I should have put it?

I'm using some plugin to make PHP code inside the article.
I'm using MySQLi.
I just see this code and I think I want this as my reference but I don't know what should I put in my source code.

Kevin Brown-Silva
  • 40,873
  • 40
  • 203
  • 237
  • **Don't** use `mysql_*` as they are deprecated. Look at Joomla documentation and use the API – Lodder Mar 05 '15 at 07:57
  • what do you mean by API? and can you give me an example(if you're not busy can you make me the source code in order to get what i want?) of a code that uses mysqli code? please? – Roy Lester Santos Mar 05 '15 at 08:01
  • If you want to make a form, I would suggest making a small [Module](https://docs.joomla.org/J3.x:Creating_a_simple_module/Developing_a_Basic_Module). The make full use of the [Database API](https://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase) – Lodder Mar 05 '15 at 08:06
  • oh ok but how can i connect an article with that module? for example i have this form and the submit button links to this article https://localhost/joomla/index.php/admissions/AddRegisteredCars.php so what should i do sorry for more question :( – Roy Lester Santos Mar 05 '15 at 08:08
  • I've looked through your other questions to see similarities. I really think you need to stop, take a deep breath and slowly start going through the documentation and other Stackoverflow questions to see how Joomla works and how to do things. It's a CMS, so it's very different to making a basic PHP site – Lodder Mar 05 '15 at 08:14
  • Imporved code formatting removed unnecessary text. – csharpwinphonexaml Mar 05 '15 at 17:24
  • Welcome to Stack Overflow! I've edited out the file name from the title and tried to improve the wording of your question within the body. If it looks like I missed something, or I didn't understand the question, feel free to leave a comment in response or edit the question again with what you actually meant. – Kevin Brown-Silva Mar 05 '15 at 18:42

0 Answers0