Jump to content
nueva123

I want to insert into table of my DB but it doesn't work

Recommended Posts

:rolleyes:people HiI need to insert a row into a table of my database, then here is a brief code as an example, anyone that would help me to resolve PLEASE :) <?php require_once('../Connections/elena.php'); ?><?phpfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue;}$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO boys(married, name) VALUES (%s, %s)", GetSQLValueString($_POST['married'], "int"), GetSQLValueString($_POST['name'], "text")); mysql_select_db($database_elena, $elena); $Result1=mysql_query($insertSQL,$elena) or die(mysql_error()."- Query -".$insertSQL); $insertGoTo = "index.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo));}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Process Example</title><style type="text/css"><!--body,td,th { color: #FFFFFF;}body { background-color: #0099CC;}.Estilo1 {font-family: Arial, Helvetica, sans-serif}.Estilo5 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; }.Estilo6 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bold; }--></style></head><body><form method="post" name="form1" action="<?php echo $editFormAction; ?>"> <input type="hidden" name="MM_insert" value="form1"></form><form action ="<?php echo $editFormAction; ?>"method="POST" enctype="multipart/form-data" name= "form1" > <h1><span class="Estilo1">Title</span></h1> <fieldset id="married"> <input name="married" type="radio" value="Yes" id="married_yes" <?php $OK = isset($_POST["married"]) ? true : false; if ($OK && isset($missing) && $_POST["married"] == "Yes") { ?> checked = "checked" <?php } ?>/> <label for = "married_yes">Si</label> <input name = "married" type="radio" value="No" id="married_no" <?php if ($OK && isset($missing) && $_POST["married"] == "No") { ?> checked="checked" <?php } ?> /> <label for ="married_no">No</label> </p> </fieldset> <p class="Estilo5">Name</p></form><p> <label> <textarea name="name" cols="95" rows="1" id="name"></textarea> </label></p> <label>Save <input name="submit" type="Submit" value="Save" /> </label></body></html>Thank You I'm expecting a help, when I know to program in PHP I will help too, I know VisualFox 9 but I need to learn PHPmy email is nueva123@hotmail.com

Share this post


Link to post
Share on other sites

You have 2 forms on the page. The input in the first form needs to be in the second one.We're willing to help you learn how to use PHP, but don't come here expecting people to do your work for you. We're here to help you learn, if you have questions about why something doesn't work, expect to get answers that tell you how to figure out what the problem is yourself.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...