Link to home
Start Free TrialLog in
Avatar of Johnny
JohnnyFlag for United States of America

asked on

how to get info saved to database (my code is not working)

im gonna do this short as maybe i messed it up and i'm not seeing the problem.
        alert(signaturePad.toDataURL());
        // ** Save to database how **//
        /**/
        //e.preventDefault();
		  //var name = $("#name").val();
		  var image_info = signaturePad.toDataURL();
		  var dataString = 'image='+image_info+'';
		  $.ajax({
		    type:'POST',
		    data:dataString,
		    url:'save_to_mysqli.php',
		    success:function(data) {
		      alert(data);
		    }
		    });

Open in new window


alert(signaturePad.toDataURL()); alert fires fine. doesn't seam to be running the save_to_mysqli.php file
how can i debug this to find out if its working, and or is there something wrong with code i'm using.
i am trying to use jquery inside javascript i have jquery loaded with <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
the code of
if (jQuery) {alert("jQuery library is loaded!");} else {alert("jQuery library is not found!");}

Open in new window

fires off fine
what am i missing that this is not working please
thank you in advance for any code or help you may provide.
Avatar of Gary
Gary
Flag of Ireland image

Do you have a link to look at?
Avatar of Johnny

ASKER

http://completelocal.info/sig/sig.php

its the save part im having issues with
jQuery is JavaScript.  Please show us the PHP that is in this script:

save_to_mysqli.php
In this function
saveButton.addEventListener("click", function (event) {

You are passing the object as event but later on you are targeting just e
e.preventDefault();

This should be
event.preventDefault();
Avatar of Johnny

ASKER

@Ray_Paseur
<?php

    // version:
    //'save_to_mysqli.php
$link = mysqli_connect("localhost", "local_xxxx", "xxxxx", "local_xxxxx");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

//mysqli_query($link, "CREATE TABLE myCity LIKE City");

$query = "INSERT INTO signatures VALUES (NULL, 'FakeName Johnny', '".$_POST['image']."', NULL, '".$_SERVER['REMOTE_ADDR']."', NOW(), NULL)";
 
if (mysqli_query($link, $query)) 
{
printf ("New Record has id %d.\n", mysqli_insert_id($link));
}
else 
{
//printf("query failed: %s\n", mysqli_error());
//echo "error need to find out how to print mysqli error";
throw new Exception(mysqli_error($link));
    //exit();
}


/* drop table */
//mysqli_query($link, "DROP TABLE myCity");

/* close connection */
mysqli_close($link);
?>

Open in new window

Avatar of Johnny

ASKER

@GaryC123

e.preventDefault();

is commented out is it need for the function to operate and also changed to event.preventDefault();?
In the page you linked to it is not commented out.
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Johnny

ASKER

@ GaryC123
that was it i had the wrong path for the save file..
i dont think i would have ever od found it thank you
Avatar of Johnny

ASKER

thank you again