Jump to content


Photo

I've started coding my script


  • Please log in to reply
5 replies to this topic

#1 anticore

anticore
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 11 March 2006 - 04:46 PM

I'm trying to create a system to store user rides in a table to create a simple gallery
I've started coding it and this is what i got.

$db = mysql_connect ("$host", "$username", "$password");
mysql_select_db ("$databasename", $db);
 
//Start add article
if($action=="add")
{
 
//If they have entered data into the form, do this
if($name||$year||$yearcat||$details||$image1||$image2||$image3||$image4||$smpic)
{
 
$insertIt=mysql_query("INSERT INTO $tablename (`name`, `year`, `yearcat`, `details`, `image1`, `image2`, `image3`, `image4`, `smpic`) VALUES ('$name', '$year', '$yearcat', '$details', '$image1', '$image2', '$image3', '$image4', '$smpic')",$db); 
}
if($insertIt)
{
echo " <i>$name</i> has been successfully added<br>";
}
else
{
echo "Sorry there has been an error, please try again<br>"; 
}
}
 
//give form
else
{
echo"
 
<form id=\"form1\" name=\"form1\" method=\"post\" action=\"$PHP_SELF\">
  <label>Name
  <input name=\"name\" type=\"text\" id=\"name\" maxlength=\"30\" /> 
  </label>
  <p>
    <label>Year
    <input name=\"year\" type=\"text\" id=\"year\" size=\"6\" maxlength=\"4\" />
    </label> 
  </p>
  <p>
    <label>Year Catagory
    <select name=\"yearcat\" id=\"yearcat\">
      <option value=\"05up\">05up</option>
      <option value=\"9904\">9904</option> 
      <option value=\"9498\">9498</option>
      <option value=\"8793\">8793</option>
      <option value=\"7986\">7986</option>
      <option>Choose One</option> 
    </select>
    </label>
  </p>
  <p>
    <label>Details
    <textarea name=\"details\" cols=\"40\" rows=\"6\" id=\"details\" maxlength=\"255\"></textarea> 
    </label>
  </p>
  <p>Locations of Images:</p>
  <p>
    <label>Image1
    <input name=\"image1\" type=\"text\" id=\"image1\" /> 
    </label>
  </p>
  <p>
    <label>Image 2
    <input name=\"image2\" type=\"text\" id=\"image2\" />
    </label>
  </p>
  <p> 
    <label>Image 3
    <input name=\"image3\" type=\"text\" id=\"image3\" />
    </label>
  </p>
  <p>
    <label>Image 4
    <input name=\"image4\" type=\"text\" id=\"image4\" /> 
    </label>
  </p>
  <p>
    <label>Thumbnail Image
    <input name=\"smpic\" type=\"text\" id=\"smpic\" />
    </label>
</p>
  <p><input name=\"action\" type=\"hidden\" value=\"add\">
 
<input type=\"submit\" value=\"Add Article\"></p>
</form>
";
?>

i tried doing userride.php?add to test this and all i got was a blank page


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 11 March 2006 - 04:57 PM

Try changing:
if($action=="add")
to
if($_GET['action']=="add")
Only chnage it if you have register_globals set to Off.

If you still dont get anything try going to this instead userride.php?add=1

As in order for the add variable to be sent it needs to have a value assign to it, in this case 1

#3 anticore

anticore
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 11 March 2006 - 05:25 PM

Still nothing :(
i changed it back tried ?add=1 and still nothing.
Maybe I should take the form out of the if statement?

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 11 March 2006 - 05:28 PM

Sorry try this instead:
userride.php?action=add

#5 anticore

anticore
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 11 March 2006 - 05:35 PM

nothing. I also tried add a } after the form echo i didnt close the statement i think but still nothing.

#6 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 13 March 2006 - 08:28 AM

Also your if statement with all the variables separated by || is not going to do what you want. If register globals is turned off (I strongly recommend off for security reasons) then you must use something like $_GET['name'] to return the value of the variable and if you are processing it from a form then you want all values to be entered and would need to use && (and) not || (or). "or" will return the statement true and fire the code inside the if after one of the conditions returns true. "and" will return true and fire the code inside the if only if all conditions are met. Grouping them all together like this will keep you from returning an accurate error to the end-user so they don't know what was wrong with what they submitted. Instead, I suggest this:

if ( $_GET['name'] == "" ) die("<p>You didn't enter a name.</p>\r\n");
if ( $_GET['year'] == "" ) die("<p>You didn't enter a year.</p>\r\n");
if ( $_GET['yearcat'] == "" ) die("<p>You didn't enter a yearcat.</p>\r\n");
if ( $_GET['details'] == "" ) die("<p>You didn't enter any details.</p>\r\n");
if ( $_GET['image1'] == "" ) die("<p>You didn't enter image1.</p>\r\n");
if ( $_GET['image2'] == "" ) die("<p>You didn't enter image2.</p>\r\n");
if ( $_GET['image3'] == "" ) die("<p>You didn't enter image3.</p>\r\n");
if ( $_GET['image4'] == "" ) die("<p>You didn't enter image4.</p>\r\n");
if ( $_GET['smpic'] == "" ) die("<p>You didn't enter smpic.</p>\r\n");

The draw back of this it will only tell them one error at a time. Alternatively instead of die you can set $error = "" then parse each if statement and where it says die above do $error .= "<p>You didn't do whatever.</p>\r\n"; once all the if statements are done you can do if ( strlen($error) > 0 ) die($error);. That will return all errors and stop the script from going any further.

If you need a more indepth explanation, let me know.

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users